package com.ll.controller;

import com.ll.entity.Product;
import com.ll.service.ProductService;
import com.ll.util.FileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/product")
@CrossOrigin // 允许跨域访问
public class ProductController {
    @Autowired
    ProductService productService;

    //查询所有商品
    @RequestMapping("/list")
    public List<Product> list(@RequestBody Product product){
        return productService.list(product);
    }

    //添加商品
    @RequestMapping("/add")
    public String add(@RequestBody Product product){
        return productService.add(product);
    }

    @RequestMapping("/detail")
    public Product detail(Integer productId){
        return productService.detail(productId);
    }
    @RequestMapping("/update")
    public String update(@RequestBody Product product){
        return productService.update(product);
    }

    @RequestMapping("/delete")
    public String delete(Integer productId){
        return productService.delete(productId);
    }
    @RequestMapping("/upload")
    public String upload(MultipartFile file){
        System.out.println("上传图片");
        return FileUtil.upload(file);
    }
}
